package own.application.global.util;

import java.io.UnsupportedEncodingException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;

public class LoadProperties {

	public static Map<String, Object> getAllMessage(String propertyName)
			throws UnsupportedEncodingException {
		// 获得资源包
		ResourceBundle rb = ResourceBundle.getBundle(propertyName.trim());
		// 通过资源包拿到所有的key
		Enumeration<String> allKey = rb.getKeys();
		// 遍历key 得到 value
		Map<String, Object> map = new HashMap<String, Object>();
		while (allKey.hasMoreElements()) {
			String key = allKey.nextElement();
			String value = new String(rb.getString(key).getBytes("iso-8859-1"),
					"utf-8");
			map.put(key, value);
		}
		return map;
	}

	public static String getValue(String propertyName, String key)
			throws UnsupportedEncodingException {
		// 获得资源包
		ResourceBundle rb = ResourceBundle.getBundle(propertyName.trim());
		return new String(rb.getString(key).getBytes("iso-8859-1"), "utf-8");
	}
}
